﻿@using XStudio.XCRF.Data.Entities.CureInfo
@using XStudio.XCRF.Web.Models.CureInfo
@model CureInfo
@{
    ViewBag.Title = "治疗信息编辑";
    Layout = "~/Views/Shared/Master.cshtml";
}
@{Html.Telerik().Window().Name("CureInfoEditWindouw").Title("治疗信息编辑").HtmlAttributes(new { @class = "ContentLargeWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
@{using (Ajax.BeginForm<CureInfoController>(c => c.CureInfoEdit(null),
   new AjaxOptions { OnBegin = "BeforeSend", OnSuccess = "OnSuccess", OnFailure = "OnError" }))
  {
      <table>
        <tr>
            <th>治疗时间：</th>
            <td>
                @Html.HiddenFor(model => model.ID)
                @Html.HiddenFor(model => model.CRFID)
                @Html.DateEditorFor(model => model.Time)
            </td>
        </tr>
      </table>
      @panelBar()
      @Html.Partial("CureEvaEdit", Model)
      <input type="submit" value="提交" />
  }
  }
 </text>).Render();
}

@helper panelBar()
    {
        Html.Telerik().PanelBar()
        .Name("CureInfoMenu")
        .HtmlAttributes(new { @class = "ContentWindow" })
        .Items(items =>
        {
            items.Add().Text("主诉")
                .Content(@<text>
              @Html.TextBoxFor(model => model.Complaint)
              </text>);
            items.Add().Text("症状")
                  .Content(@<text>
              @Html.Partial("SymptomEdit", Model)
              </text>);
            items.Add().Text("体征")
                .Content(@<text>
              @Html.TextBoxFor(model => model.VitalSign)
              </text>);
            items.Add().Text("舌象")
                .Content(@<text>
              @Html.Partial("TongueEdit", Model)
              </text>);
            items.Add().Text("脉象")
                .Content(@<text>
              @Html.Partial("PulseEdit", Model)
              </text>);
            items.Add().Text("主证")
                .Content(@<text>
              @Html.DiseaseEditorFor(model => model.PrimarySyms)
              </text>);
            items.Add().Text("次证")
                .Content(@<text>
              @Html.DiseaseEditorFor(model => model.SubSyms)
              </text>);
            items.Add().Text("草药")
                .Content(@<text>
              @Html.TextAreaFor(model => model.Herbs)
              <input type="button" value="生成草药" onclick="GenerateHerb();" />
              </text>);
            items.Add().Text("不良反应")
                .Content(@<text>
              @Html.Partial("ReactionEdit", Model)
              </text>);
            items.Add().Text("复发转移情况")
                .Content(@<text>
              @Html.Partial("TransferEdit", Model)
              </text>);
            items.Add().Text("中成药、中药注射液")
                .Content(@<text>
              @Html.Partial("InjectGridView", Model)
              </text>);
            items.Add().Text("化疗")
                .Content(@<text>
              @Html.Partial("CureChemoGridView", Model)
              </text>);
            items.Add().Text("放疗")
                .Content(@<text>
              @Html.Partial("CureRadioGridView", Model)
              </text>);
            items.Add().Text("超声刀")
                .Content(@<text>
              @Html.Partial("CureSoundGridView", Model)
              </text>);
            items.Add().Text("伽马刀")
                .Content(@<text>
              @Html.Partial("CureGammaGridView", Model)
              </text>);
            items.Add().Text("其他治疗")
                .Content(@<text>
              @Html.Partial("CureOtherCureGridView", Model)
              </text>);
        }).Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("adding").Title("系统提示")
    .Buttons(buttons => buttons.Clear())
    .ClientEvents(window => window.OnOpen("OnAddingOpen"))
    .Content(
@<text>
正在添加，请稍后...
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("addError").Title("系统提示")
    .Buttons(buttons => buttons.Close())
    .ClientEvents(window => window.OnOpen("OnAddErrorOpen"))
    .Content(
@<text>
出现错误，请重试！
</text>)
    .Render();
}
<script type="text/javascript">
    function OnAddingOpen() {
        $("#adding").data("tWindow").center();
    }
    function OnAddErrorOpen() {
        $("#addError").data("tWindow").center();
    }
    function BeforeSend() {
        $("#adding").data("tWindow").open();
    }
    function OnSuccess(data) {
        if (data.ID) {
            var url = "@(Url.Action<CureInfoController>(c => c.CureInfoDetail(Guid.Empty)))";
            url = url.replace("@Guid.Empty", data.ID);
            window.location = url;
        } else {
            OnError();
        }
    }
    function OnError() {
        $("#addError").data("tWindow").open();
        $("#adding").data("tWindow").close();
    }
    function CheckForm() {
        alert("请输入您姓名!");
        if (document.form.Name.value.length == 0) {
            alert("请输入您姓名!");
            document.form.Name.focus();
            return false;
        }
        return true;
    }
    function GenerateHerb() {
        var countAll = @DiseaseInfo.Diseases.Count();
        var count = 0;
        var data = {};
        for(var i=0; i<countAll; i++) {
            var chkbox = $("#PrimarySyms_" + i);
            if(chkbox.attr("checked") == "checked") {
                var hidID = $("#PrimarySyms_" + i + "_ID");
                data["diseaseIDs[" + count + "]"] = hidID.val();
                count++;
            }
        }
        for(var i=0; i<countAll; i++) {
            var chkbox = $("#SubSyms_" + i);
            if(chkbox.attr("checked") == "checked") {
                var hidID = $("#SubSyms_" + i + "_ID");
                data["diseaseIDs[" + count + "]"] = hidID.val();
                count++;
            }
        }
        $.ajax({
            url:"@(Url.Action<CureInfoController>(c=>c.GenerateHerb(null)))",
            type: "post",
            data: data,
            success: function(data) {
                if(data.success) {
                    var txtHerb = $("#Herbs");
                    txtHerb.val(data.strNames);
                } else {
                    alert("Error");
                }
            },
            error: function() {
                alert("error");
            }
        });
    }

    $(".t-item").live('click', function () {
        if($(this).parent().children().first().html() == "淡白舌"){
        if ($(this).html() == "未知") {
            $("#TongueColorOther").show();
        } else {
            $("#TongueColorOther").hide();
        }
        }else if($(this).parent().children().first().html() == "苍老舌"){
        if ($(this).html() == "未知") {
            $("#TongueShapeOther").show();
        } else {
            $("#TongueShapeOther").hide();
        }
        }else if($(this).parent().children().first().html() == "颤动"){
        if ($(this).html() == "未知") {
            $("#TongueStatusOther").show();
        } else {
            $("#TongueStatusOther").hide();
        }
        }else if($(this).parent().children().first().html() == "厚"){
        if ($(this).html() == "未知") {
            $("#FurCharacterOther").show();
        } else {
            $("#FurCharacterOther").hide();
        }
        }else if($(this).parent().children().first().html() == "白苔"){
        if ($(this).html() == "未知") {
            $("#FurColorOther").show();
        } else {
            $("#FurColorOther").hide();
        }
        }else if($(this).parent().children().first().html() == "浮脉"){
        if ($(this).html() == "未知") {
            $("#FloatingPulseClassOther").show();
        } else {
            $("#FloatingPulseClassOther").hide();
        }
        }else if($(this).parent().children().first().html() == "沉脉"){
        if ($(this).html() == "未知") {
            $("#DeepPulseClassOther").show();
        } else {
            $("#DeepPulseClassOther").hide();
        }
        }else if($(this).parent().children().first().html() == "涩脉"){
        if ($(this).html() == "未知") {
            $("#SlowPulseClassOther").show();
        } else {
            $("#SlowPulseClassOther").hide();
        }
        }else if($(this).parent().children().first().html() == "促脉"){
        if ($(this).html() == "未知") {
            $("#RapidPulseClassOther").show();
        } else {
            $("#RapidPulseClassOther").hide();
        }
        }else if($(this).parent().children().first().html() == "微脉"){
        if ($(this).html() == "未知") {
            $("#FeeblePulseClassOther").show();
        } else {
            $("#FeeblePulseClassOther").hide();
        }
        }else if($(this).parent().children().first().html() == "实脉"){
        if ($(this).html() == "未知") {
            $("#ExcessPulseClassOther").show();
        } else {
            $("#ExcessPulseClassOther").hide();
        }
        }
     });
</script>